/**
 * 
 */
package com.mc.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.mc.pojo.Person;

/**
 * @author w.weizhen
 *
 *lambda 主要测试方法
 *
 */
public class LambdaMain {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
//        listToMap();
        
    	//定义list集合
    	List<Person> list = Arrays.asList(new Person("0", "哈哈"), new Person("1", "哈哈"), new Person("2", "嘿嘿"), new Person("3", "呵呵"));
    	//从list集合中，取出字段name的列表并去重
    	List<String> names = list.stream().map(Person::getName).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
        System.out.println(names);
        names = list.stream().map(Person::getName).collect(Collectors.toList());
        System.out.println(names);
        
    }
    
    //list转map测试方法
    private static void listToMap() {
        
        List<Person> ps = new ArrayList<Person>();
        for (int i = 0; i < 10; i++) {
            Person p = new Person();
            p.setId(Math.floor(Math.random() * Math.floor(5))+"");
            p.setName(Math.floor(Math.random() * Math.floor(5))+"");
            ps.add(p);
        }
        
        
    }
    
    
    
    
}